package com.lovo.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lovo.commom.util.ConstantUtil;
import com.lovo.sys.bean.AdminBean;
import com.lovo.sys.bean.UserBean;
import com.lovo.sys.mapper.IAdminMapper;
import com.lovo.sys.service.IAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class AdminServiceImpl implements IAdminService {
    @Autowired
    private IAdminMapper adminMapper;

    @Override
    public void add(AdminBean admin) {
        adminMapper.insert(admin);
    }

    @Override
    public void updatePwd(int id, String newPwd) {
        AdminBean admin = adminMapper.selectById(id);
        admin.setPwd(newPwd);
        adminMapper.updateById(admin);
    }

    @Override
    public void del(int id) {
        adminMapper.deleteById(id);
    }

    @Override
    public AdminBean login(String userName, String pwd) {
        QueryWrapper qw = new QueryWrapper<>();
        qw.eq("a_userName", userName);
        qw.eq("a_pwd", pwd);
        return adminMapper.selectOne(qw);
    }

    @Override
    public IPage findAll(int pageNO) {
        return adminMapper.selectPage(new Page<>(pageNO, ConstantUtil.SIZE), null);
    }
}
